//@author A0101200R

package testcases;

import static org.junit.Assert.assertEquals;
import logic.ScheduleDisplay;
import logic.ScheduleSearcher;
import logic.ScheduleSorter;

import org.junit.Test;

import storage.ScheduleEvent;
import storage.Storage;

public class ScheduleDisplayTest {
	
	// list of constants
	private static final int EVENT_TYPE_FLOATING = 0;
	private static final int EVENT_TYPE_DEADLINE = 1;
	private static final int EVENT_TYPE_TIMED = 2;
	
	private static final String NEW_LINE = "\n" + "\n";
	private static final String FULL_STOP = ". ";
	
	// list of commands
	private static final String COMMAND_ALL = "all";
	private static final String COMMAND_DONE = "done";
	private static final String COMMAND_UNDONE = "undone";
	private static final String COMMAND_TODAY = "";
	
	// list of messages
	private static final String MSG_TODAY_NO_TASKS = "There are no tasks today.";
	
	// list of variables from other classes
	Storage storage = new Storage("testDisplay.txt");
	ScheduleSorter sorter = new ScheduleSorter(storage);
	ScheduleSearcher searcher = new ScheduleSearcher(storage, sorter);
	ScheduleEvent floatingTask, deadlineTask1, deadlineTask2, timedTask;
	ScheduleDisplay display = new ScheduleDisplay(storage, sorter, searcher);
	
	private String outputDeadline1() {
		deadlineTask1 = new ScheduleEvent(EVENT_TYPE_DEADLINE, "test for deadline task 1", "02052014", "0900");
		storage.addEvent(deadlineTask1);
		int index = storage.getEventIndex(deadlineTask1);
		storage.markEventDone(index+1);
		
		String deadline = deadlineTask1.toString();
		
		return deadline;
	}
	
	private String outputDeadline2() {
		deadlineTask2 = new ScheduleEvent(EVENT_TYPE_DEADLINE, "test for deadline task 2", "03052014");
		storage.addEvent(deadlineTask2);
		
		String deadline = deadlineTask2.toString();
		
		return deadline;
	}
	
	private String outputTimed() {
		timedTask = new ScheduleEvent(EVENT_TYPE_TIMED, "test for timed task", "04052014", "0900", "1300");
		storage.addEvent(timedTask);
		int index = storage.getEventIndex(timedTask);
		storage.markEventDone(index+1);
		
		String timed = timedTask.toString();
		
		return timed;
	}
	
	private String outputFloat() {
		floatingTask = new ScheduleEvent(EVENT_TYPE_FLOATING, "test for floating task", "99999999");
		storage.addEvent(floatingTask);
		String floating = floatingTask.toString();
		
		return floating;
	}
	
	@Test
	public void testDisplay() {
		storage.clearAllEvents();
		String deadline1 = outputDeadline1();
		String deadline2 = outputDeadline2();
		String timed = outputTimed();
		String floating = outputFloat();
		int index = 1;
		
		String expectedAll = index + FULL_STOP + deadline1 + NEW_LINE 
							+ (index+1) + FULL_STOP + deadline2 + NEW_LINE
							+ (index+2) + FULL_STOP + timed + NEW_LINE
							+ (index+3) + FULL_STOP + floating;
		
		String expectedDone = index + FULL_STOP + deadline1 + NEW_LINE
							+ (index+2) + FULL_STOP + timed + NEW_LINE;
		
		String expectedUndone = (index+1) + FULL_STOP + deadline2 + NEW_LINE 
							+ (index+3) + FULL_STOP + floating;
		
		String expectedToday = MSG_TODAY_NO_TASKS;
		
				
		assertEquals(expectedAll, display.displayEvents(COMMAND_ALL));
		assertEquals(expectedDone, display.displayEvents(COMMAND_DONE));
		assertEquals(expectedUndone, display.displayEvents(COMMAND_UNDONE));
		assertEquals(expectedToday, display.displayEvents(COMMAND_TODAY));
		
	}

}
